package util;

/**
 * @author : xuzhennan @Project : dot_blog @Package : com.dot.blog.common.util
 * @email : xuzhennan@58.com
 * @date : 2021年03月25日 下午10:47
 */
public class ResponseData {
  private int code;
  private Object data;
  private String msg;

  public ResponseData() {}

  public ResponseData(int code) {
    this.code = code;
  }

  public ResponseData(int code, Object data) {
    this.code = code;
    this.data = data;
  }

  public ResponseData(int code, Object data, String msg) {
    this.code = code;
    this.data = data;
    this.msg = msg;
  }

  public ResponseData(int code, String msg) {
    this.code = code;
    this.msg = msg;
  }

  public static ResponseData buildSuccess() {
    return new ResponseData(0);
  }

  public static ResponseData buildSuccess(Object data) {
    return new ResponseData(0, data);
  }

  public static ResponseData buildSuccess(Object data, String msg) {
    return new ResponseData(0, data, msg);
  }

  public static ResponseData buildError() {
    return new ResponseData(1);
  }

  public static ResponseData buildError(String msg) {
    return new ResponseData(1, "", msg);
  }

  public static ResponseData buildError(String msg, int code) {
    return new ResponseData(code, "", msg);
  }

  public static ResponseData buildEx(String msg) {
    return new ResponseData(500, "", msg);
  }

  public int getCode() {
    return code;
  }

  public void setCode(int code) {
    this.code = code;
  }

  public Object getData() {
    return data;
  }

  public void setData(Object data) {
    this.data = data;
  }

  public String getMsg() {
    return msg;
  }

  public void setMsg(String msg) {
    this.msg = msg;
  }

  @Override
  public String toString() {
    return "JsonData{" + "code=" + code + ", data=" + data + ", msg='" + msg + '\'' + '}';
  }
}
